package com.kbt.listener;

import android.app.Activity;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.widget.PopupWindow;
import com.kbt.activity.LoginActivity;
import com.kbt.activity.R;
import com.kbt.base.BaseApplication;
import com.kbt.model.data.GoodInfo;
import com.kbt.model.data.GoodRoadInfo;
import com.kbt.model.data.ShopInfo;
import com.kbt.ui.AddCarPopWindow;
import com.kbt.ui.BuyNowPopWindow;
import com.kbt.util.data.StaticData;

/**
 * @author zhgk
 * @package: com.kbt.listener
 * @TODO: 立即购买按钮事件
 * @data: 2015/8/11 10:53
 * @version: V1.0
 */
public class clickOpenWindowListener implements View.OnClickListener {

    //当前活动的Acitvity
    private Activity activity;
    //窗口显示的位置
    private View view;

    private int windowType;

    //窗体弹出来源
    private int popWindowFrom;

    private ShopInfo goodInfo;


    /**
     * 构造函数
     *
     * @param activity
     * @param view
     */
    public clickOpenWindowListener(Activity activity, View view, int popupWindowType, int popFrom) {
        this.activity = activity;
        this.view = view;
        this.windowType = popupWindowType;
        this.popWindowFrom = popFrom;
    }

    public clickOpenWindowListener(Activity activity, View view, int popupWindowType, int popFrom, ShopInfo goodInfo) {
        this.activity = activity;
        this.view = view;
        this.windowType = popupWindowType;
        this.popWindowFrom = popFrom;
        this.goodInfo = goodInfo;
    }

    /***
     * 单击事件,打开窗口
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        PopupWindow popupWindow=null;
        switch (windowType) {
            case StaticData.PopWindow_addCar:
                if(BaseApplication.getInstance().isLogin()){
                    popupWindow = new AddCarPopWindow(activity, popWindowFrom,goodInfo.getGoods_id(),goodInfo.getGoods_icon(),goodInfo.getGoods_new_price(),goodInfo.getStore_counts());
                }else{
                    Intent intent = new Intent(activity, LoginActivity.class);
                    activity.startActivity(intent);
//                    activity.finish();
                }
//                popupWindow = new AddCarPopWindow(activity, popWindowFrom,goodInfo.getGoods_id());
                break;
            case StaticData.PopWindow_buyNow:
                if(BaseApplication.getInstance().isLogin()){
                    popupWindow = new BuyNowPopWindow(activity,goodInfo);
                }else{
                    Intent intent = new Intent(activity, LoginActivity.class);
                    activity.startActivity(intent);
//                    activity.finish();
                }
                break;
            default:
                popupWindow = new PopupWindow();
                break;
        }
        if(popupWindow!=null) {
            popupWindow.showAtLocation(activity.findViewById(R.id.info_info_img_layout),
                    Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        }
        //设置layout在PopupWindow中显示的位置
    }
}
